package com.hmy.singleton;
/**
 * 单例模式：确保一个类只有一个实例，并且提供全局的访问点
 *
 */
public class Singleton4 {
	//利用volatile保证对象的实时更新
	private volatile static Singleton4 uniqueSingleton;
	
	//构造器私有化
	private Singleton4() {
		
	}
	//双重检查加锁
	public  static Singleton4 getSingletonInstance() {
		if (uniqueSingleton == null) {
			synchronized (Singleton4.class) {
				if (uniqueSingleton == null) {
					uniqueSingleton = new Singleton4();
				}
			}
		}
		return uniqueSingleton;
	}
	
}
